<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" > 

<html>
<head>
<title id="ttlTitle" runat="Server">Rules</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<?XML:NAMESPACE PREFIX="WM">
<?XML:NAMESPACE PREFIX="MYTREE">
<?XML:NAMESPACE PREFIX="amfc">
<?IMPORT NAMESPACE="WM"     IMPLEMENTATION="/Include/HTC/dropmenu.htc" >
<!--?IMPORT NAMESPACE="MYTREE" IMPLEMENTATION="/webctrl_client_d/1_0/treeview.htc" -->
<?IMPORT NAMESPACE="MYTREE" IMPLEMENTATION="/include/HTC/TreeEx/treeex.htc" >
<?IMPORT namespace="amfc" implementation="/include/htc/datagrid.htc">
<LINK rel="stylesheet" type="text/css" href="/CSS/Outlook.css">
<LINK rel="stylesheet" type="text/css" href="/CSS/navbar.css">
<!--LINK rel="stylesheet" type="text/css" href="/Common/Decision.css">
<LINK rel="stylesheet" type="text/css" href="Decision.css"-->
<STYLE>@media all{move\:piece{behavior: url(movable.htc);cursor: move;}}
	.lableLoan {background-color:gainsboro}
	.toolTip {BACKGROUND-COLOR: infobackground; BORDER-BOTTOM: 1px outset; BORDER-LEFT: thin outset; BORDER-RIGHT: 1px outset; BORDER-TOP: thin outset;DISPLAY: none; FONT-FAMILY: monospace; FONT-SIZE: 8pt; FONT-WEIGHT: bold;PADDING-LEFT: 2px; PADDING-RIGHT: 2px;}
	.buttonActive{BORDER-BOTTOM: 1px outset; BORDER-LEFT: thin outset; BORDER-RIGHT: 1px outset; BORDER-TOP: thin outset;}
	.buttonInActive{	BORDER-BOTTOM: 1px solid menu; BORDER-LEFT: thin solid menu; BORDER-RIGHT 1px solid menu; BORDER-TOP: thin solid menu;}
	.ANDLable{color:brown}
	.ORLable {color:darkgreen}
	.flatButton {BORDER: 1px solid;}
</STYLE>
</head>
<body MS_POSITIONING="GridLayout" style="OVERFLOW: auto; BACKGROUND-COLOR: infobackground" onload="page_Load()"	oncontextmenu="if(!event.ctrlLeft)return bodyContextMenu()"	onclick="oTree.selectedNodeIndex='10000'" onkeypress="if(event.keyCode==27)oTree.selectedNodeIndex='10000'"	id="ws">
<FIELDSET style="BACKGROUND-COLOR: buttonface" onclick="if(this==event.srcElement||tblMenu==event.srcElement)tblMenu.style.display=tblMenu.style.display?'':'none'">
		<TABLE border="0" cellpadding="2" cellspacing="1" id="tblMenu" style="display:none">
			<TR>
				<TD colspan="2" nowrap style="PADDING-BOTTOM: 2px" >
						<!--INPUT type="image" src="Common/Images/Delete.gif" title="Delete Bank" onclick="deleteBank()" style="VERTICAL-ALIGN: middle;BORDER:0"-->
						<SPAN style="border:1 solid black;padding-left:5px;margin-right:15px;">
							<INPUT type="image" SRC="Common/Images/Refresh.gif" onclick="dataBind(oTree)" title="Refresh" style="VERTICAL-ALIGN: middle;BORDER:0"> 
							<INPUT type="image" src="Common/Images/Collapse.gif" title="Collapse All" onclick="collapseAll(this)" style="VERTICAL-ALIGN: middle;BORDER:0">
							<INPUT type="image" src="Common/Images/Doc.gif" title="Show Docs" onclick="showDocs()" style="BORDER:0;VERTICAL-ALIGN: middle">
							<INPUT type="image" src="Common/Images/Binoculars.gif" title="Show Rule" onclick="showRuleDialog()" style="BORDER:0;VERTICAL-ALIGN: middle">
							<INPUT type="image" src="Common/Images/Tools.gif" title="Build Rules" onclick="buildRules()" style="BORDER:0;VERTICAL-ALIGN: middle">
							<INPUT type="checkbox" datasrc="#xmlInfo" datafld="RealTime" onclick="return changeRealTime(this)" style="border:none;VERTICAL-ALIGN: middle"> RT
							<INPUT type="checkbox" datasrc="#xmlInfo" datafld="TreeDebug" onclick="return changeTreeDebug(this)" style="border:none;VERTICAL-ALIGN: middle"> TD
							<INPUT type="image" src="Common/Images/OpenCopy.gif" title="Open Copy Window" onclick="openCopyWindow()" style="BORDER:0;VERTICAL-ALIGN: middle">
						</SPAN>
				<TD align="right" nowrap>Applicant ID:
				<TD nowrap><INPUT id="txtApplID" datasrc="#xmlInfo" datafld="ApplID" onchange="changeApplID()" size="6" style="VERTICAL-ALIGN: middle">
						<INPUT type="image" SRC="Common/Images/ViewPane.gif" style="VERTICAL-ALIGN: middle;BORDER:0" onclick="showPreQual()" title="Show PreQual Form">
						<INPUT type="image" SRC="Common/Images/Ruler.gif" style="VERTICAL-ALIGN: middle;BORDER:0" onclick="getPQInfo()" title="Show PreQual Info">
			<TR>
				<TD colspan="10">
						<SPAN style="border:1 solid black;padding-left:5px;margin-right:15px;">
								Bank: <SELECT id="selBanks" runat="server" datasrc="#xmlInfo" datafld="BankID" onchange="changeBank()" style="VERTICAL-ALIGN: middle" NAME="selBanks"></SELECT>
								Program: <SELECT id="selProgs" runat="server" datasrc="#xmlInfo" datafld="ProgramID" onchange="changeProgram()" style="VERTICAL-ALIGN: middle"></SELECT>
								<INPUT type="checkbox" style="BORDER:0" onclick="doAdj()" id="chkAdj" style="VERTICAL-ALIGN: middle;BORDER:0">Adj
								<INPUT type="image" src="Common/Images/Combine_3.gif" title="Show Matrix" onclick="showMatrix()" style="BORDER:0;VERTICAL-ALIGN: middle">
								<INPUT type="image" SRC="common/Images/touchtxt.gif" title="Show Matrix Text" onclick="showMatrixText()" style="BORDER:0;VERTICAL-ALIGN: middle">
								<INPUT type="image" src="Common/Images/Table_2.gif" title="Show Rates" onclick="showRates()" style="BORDER:0;VERTICAL-ALIGN: middle">
								<INPUT type="image" SRC="common/Images/touchtxt.gif" title="Compare Rate Text" onclick="showRatesText()" style="BORDER:0;VERTICAL-ALIGN: middle">
								Tier: <SELECT id="selTiers" datasrc="#xmlInfo" datafld="Tier" onchange="changeTier(this.value)" style="VERTICAL-ALIGN: middle"></SELECT>
					</SPAN>
		</TABLE>
</FIELDSET>
<AMFC:HTCDATAGRID id="gridPQInfo" toggle
									caption="Properties" allowFilter="false" allowEdit="false" allowAdd="false" allowDelete="false" 
									style="overflow-x:visible"
									hiddenFields="lender points,applicantid,selected,bank,program"
									readOnlyFields="rec -/+,-/+ text,stips,ltv -/+"
									onFilter="getPQInfo()"></AMFC:HTCDATAGRID>
<BR>
<MYTREE:TREEVIEWEX ID="oTree" spacerWidth="0"
								 SELECTEDNODEINDEX="10000" SHOWPLUS="true" EXPANDLEVEL="1000"
								 DEFAULTSTYLE="FONT-WEIGHT: bold; FONT-SIZE: 9pt; FONT-FAMILY: monospace;COLOR:navy;white-space : pre"
								 SYSTEMIMAGESPATH="/webctrl_client_d/1_0/TreeImages/"
								 oncontextmenu="return showGLItemMenu(this)"
								 onnodebound="onDataBound(event.tree)"
								 onnodedrop="onDrop()"
								 wsSrc="GLRules.asmx?WSDL"
								 >
</MYTREE:TREEVIEWEX>
	<XML id="xmlNodeTypes">
		<TREENODETYPES>
			<TREENODETYPE TYPE="AND"	DEFAULTSTYLE="COLOR:darkred;vertical-align:top"/>
			<TREENODETYPE TYPE="OR"	DEFAULTSTYLE="COLOR:darkgreen;vertical-align:top"/>
			<TREENODETYPE TYPE="STIP"	DEFAULTSTYLE="COLOR:saddlebrown;border:1 solid black;vertical-align:bottom"/>
		</TREENODETYPES>
	</XML>
<XML id="xmlInfo">
	<ASP:LITERAL ID="ltrInfo" Runat="server"></ASP:LITERAL>
</XML>
<FORM style="margin:0px;padding:0px" id="frm" method="get" ><INPUT name="programID" type="hidden"><INPUT name="type" type="hidden"><INPUT name="suffix" type="hidden"><INPUT name="time" type="hidden"></FORM>
<FORM style="margin:0px;padding:0px" target="_search" id="frmOld" method="get" ><INPUT name="programID" type="hidden"><INPUT name="type" type="hidden"><INPUT name="suffix" type="hidden"><INPUT name="time" type="hidden"></FORM>
</body>
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
</html>
<SCRIPT language="javascript" src="/include/Common.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/DropMenu.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/RDS.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/SOAP.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/XML.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/Tree.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/Events.js"></SCRIPT>
<SCRIPT language="javascript" src="Common/GLRules.js"></SCRIPT>
<SCRIPT language="javascript">
var GL_PREQUAL_URL = "/Manager/PreQual/PreQualCommon.aspx?ApplID=";
var prmHideMenu = getParam("HideMenu");
var prmTier = getParam("Tier");
var prmAdj = getParam("Adj");
var prmBank = getParam("BankID");
var prmProg = getParam("ProgID");
var prmAppl = getParam("ApplID");
var aWindoes = new Array();
document.attachEvent("onkeydown",doEnterKey);
initWS("GLRules","GLRules.asmx?WSDL");
window.onunload = page_Unload;
tblMenu.style.display = prmHideMenu ? "none" : "";
function page_Load() {
	_applID(prmAppl);
	_adj(prmAdj);
	attachToApplInfoChanged(function(){setTimeout(function(){dataBind(oTree);getPQInfo()},100)},_applID());
	attachToDecisionInfoChanged(function(){setTimeout(function(){dataBind(oTree);getPQInfo()},100)},_applID());

	if( _bankID(prmBank) )changeBank(prmProg); 
}
function page_Unload(){
	for( var w in aWindoes )
		try{aWindoes[w].close()}catch(e){try{aWindoes[w].focus()}catch(e){}}
}
// ******************* Content Edit *************************
function startContentEdit(el){
	if( el.isContentEditable )return;
	if( el.innerText != el.innerHTML )return;
	el.contentEditable = true;
	selectElement(el);
	el.Value = el.innerText;
	el.style.backgroundColor = "white";
	el.style.border = "1 solid black";
}
function cancelContentEdit(el){
	if( event ){
		event.cancelBubble=true;
		doEnterKey();
		if( event.keyCode != 27 )return;
	}
	el.innerText = el.Value;
	el.blur();
}
function updateContent(el,updateFunction){
	if( event.keyCode == 27 )
		el.innerHTML = el.Value;
	if( el.Value != el.innerHTML )
		if( updateFunction() === false )return false;
	el.style.backgroundColor = "";
	el.style.border = "";
	el.contentEditable = false;
}
// ******************** Edit GL Label *********************************
function editGLLabel(el){
	var node = treeNodeXML(el);
	if( !_nodeAttr(node,"IsEmpty",true) )return;
	event.cancelBubble = true;
	startContentEdit(el);
}
function updateGLLabel(el){
	var node = treeNodeXML(el);
	updateContent(el,_updateGLLabel);
	// Local
	function _updateGLLabel(){
		var ret = WS(CO("UpdateGLLabel"),_nodeAttr(node,"ID"),encodeXML(el.innerHTML));
		return !showSOAPError(ret);
	}
}
// ******************** Edit GL Value *********************************
function editGLValue(el,showDialog){
	event.cancelBubble = true;
	var node = treeNodeXML(el);
	if( showDialog || eval(_nodeAttr(node,"IsEnum")) ){
		var ret = showConditions(_nodeAttr(node,"ID"),3,el)
		oTree.selectedNodeIndex = '10000';
		if( !ret )return;
		if( _applID() || _nodeAttr(node,"ColumnID") != ret.columnID ||	_nodeAttr(node,"Condition") != ret.condition )
			return dataBind(oTree);
		el.innerText = ret.valueEnum;
		selectElement(el);
		return;
	}
	if( el.isContentEditable )return;
	var bSelect = !el.isContentEditable;
	el.contentEditable = true;
	selectElement(el);
	el.Value = el.innerText;
	el.style.backgroundColor = "white";
	el.style.border = "1 solid black";
}
function cancelGLEdit(el){
	event.cancelBubble=true;
	var innerNumber = new Number(el.innerText || "0");
	if( event.keyCode == 38 && !isNaN(innerNumber)){el.innerText = formatRate(parseFloat(innerNumber)+0.125);return;}
	if( event.keyCode == 40 && !isNaN(innerNumber)){el.innerText = formatRate(parseFloat(innerNumber)-0.125);return;}
	doEnterKey();
	if( event.keyCode != 27 )return;
	el.innerText = el.Value;
	el.blur();
}
function updateGLValue(el,valueNumber){
	this.contentEditable=false;
	if( event.keyCode == 27 )
		el.innerHTML = el.Value;
	if( el.Value != el.innerText ){
		var node = treeNodeXML(el);
		var ret = WS(CO("UpdateGLValue"),_nodeAttr(node,"ID"),valueNumber,encodeXML(el.innerText));
		if( showSOAPError(ret) )return dataBind(oTree);
	}
	el.style.backgroundColor = "";
	el.style.border = "";
	el.contentEditable = false;
}
// ************************************************************************
function showRuleDialog(){
	showModelessDialog("FindRule.aspx?ProgID="+_programID(),{fnFind:showRule},"status:0;dialogHeight:250px;dialogWidth:50px;resizable:1");
}
function showRule(name,values){
	var node = _tier() ? oTree.findByAttrs(null,{Label:_tier()}) : null;
	var search = {};search[name] = values;
	oTree.showByAttrs(node,search);
}
function showDocs(){
	var node = _tier() ? oTree.findByAttrs(null,{Label:_tier()}) : null;
	oTree.showByAttrs(node,{IsStip:"true"});
}
function collapseAll(img){
	//var aImages = new Array("Collapse.gif","Expande_.gif");
	//var collapse = collapseAll.collapse = !collapseAll.collapse;
	oTree.collapseAll(true);
	//img.src = img.src.replace(/[^/]+$/i,aImages[collapse+0]);
}
function doAdj(){
	dataBind(oTree);
}
function buildRules(){
	var ret = WS(CO("BuildGLRules"),_programID());
	if( showSOAPError(ret) )return;
	if( _applID() )dataBind(oTree);
}
function onDataBound(oTree){
	if( !oTree.getChildren().length  && _bankID() )return bodyContextMenu(100,100);
	oTree.selectedNodeIndex = '10000';
	changeTier(prmTier);
	getTiers(prmTier);
	prmTier = "";
	//cropWindow();
}
function changeTier(tier){
	if( !tier )return;
	var nodes = oTree.getChildren();
	for( var i=0; i < nodes.length; i++ )
		nodes[i].setAttribute("EXPANDED",_nodeAttr(nodes[i],"Label") == tier );
}
function getTiers(tier){
	var nodes = oTree.getChildren();
	selTiers.length = 1;
	for( var i=0; i < nodes.length; i++ )
		selTiers[selTiers.length] = new Option(_nodeAttr(nodes[i],"Label"),_nodeAttr(nodes[i],"Label"));
	if( tier )selTiers.value = tier;
	else selTiers.selectedIndex = -1;
}
function showPreQual(){
	var w = open(GL_PREQUAL_URL+_applID(),"PRE_QUAL");
	w.focus();
	aWindoes.push(w);
}
function showMatrix(){
	aWindoes.push(open("GLRules.asmx/ShowGLMatrix?programid="+Math.abs(_programID())+"&Time="+new Date().valueOf()));
}
function showMatrixText(suffix){
	showGLText(frm,"Matrix","");
	showGLText(frmOld,"Matrix","Old");
}
function showGLText(frm,type,suffix){
	if( document.readyState != "complete" )return setTimeout(function(){showGLText(frm,type,suffix)},500);
	frm.action = "GLRules.asmx/ShowGLText?";
	frm.programID.value = Math.abs(_programID());
	frm.type.value = type;
	frm.suffix.value = suffix||"";
	frm.time.value = new Date().valueOf();
	frm.submit();
}
function showRatesText(){
	showGLText(frm,"Rates","");
	showGLText(frmOld,"Rates","Old");
}
function showRates(){
	var params = ["ProgramID="+Math.abs(_programID()),"ApplID="+_applID(),"Time="+new Date().valueOf()];
	aWindoes.push(open("GLRules.asmx/ShowGLRateSheets?"+params.join("&")));
}
function openCopyWindow(){
	aWindoes.push(
		open(location.href.split('?')[0]+"?ApplID="+_applID()+"&BankID="+_bankID(),"OPEN_COPY")
	);
}
var imgEdit = new Image();
imgEdit.src = "Common/Images/Edit.gif";
function showGLItemMenu(el){
	var dm = new DropMenu("mnuFly");
	if( !dm.menuID )return false;
	if( event.treeNodeIndex === undefined )return;
	var node = el.getTreeNode(event.treeNodeIndex);
	var ruleID = _nodeAttr(node,"ID",true);
	var container = _nodeAttr(node,"Container",true);
	var IsEmpty = _nodeAttr(node,"IsEmpty",true);
	dm.add("Insert Rule","showConditions("+ruleID+",1)","Common/Images/Insert.gif");
	dm.add("Combine Rules" ,"showConditions("+ruleID+",2)","Common/Images/Combine.gif");
	dm.add("Insert Level" ,"insertLevel(null,"+ruleID+")","Common/Images/InsertLevel.gif");
	//if( container ){
		dm.add("-");
		dm.add("Insert Child Rule" ,"showConditions("+ruleID+",4)","Common/Images/Expande_.gif");
		dm.add("Insert ChildLevel" ,"insertLevel("+ruleID+")","Common/Images/Expande_.gif");
	//}
	dm.add("-");
	//if( container != 1 )
		dm.add("Update",  "showConditions("+ruleID+",3,ce)","Common/Images/Edit.gif");
	dm.add("Move Up",  "shiftGL("+ruleID+",-1)","Common/Images/PointerHandUp.gif");
	dm.add("Move Down","shiftGL("+ruleID+",1) ","Common/Images/PointerHandDown.gif");
	dm.add("Move to Next Level" ,"makeItChild("+ruleID+")","Common/Images/MoveNextLevel.gif");
	dm.add("Clone" ,"cloneGL("+ruleID+")","Common/Images/Clone.gif");
	dm.add("Copy to Program" ,"copyToProgram("+ruleID+")","Common/Images/MoveNextLevel.gif");
	dm.add("-");
	dm.add("Copy" ,"showGLItemMenu.ruleID="+ruleID+";showGLItemMenu.label=\""+escape(_nodeAttr(node,"Label"))+"\"","Common/Images/MoveNextLevel.gif");
	if( showGLItemMenu.ruleID )
		dm.add("Paste" ,"pasteRule("+ruleID+",\""+escape(_nodeAttr(node,"Label"))+"\",showGLItemMenu.ruleID,showGLItemMenu.label)","Common/Images/MoveNextLevel.gif");
	if( IsEmpty ){
		dm.add("-");
		dm.add("Edit Label" ,"changeLabel("+ruleID+",\""+escape(_nodeAttr(node,"Label"))+"\")","Common/Images/Edit.gif");
	}
	dm.add("-");
	dm.add("Delete","removeGLCondition("+ruleID+",\""+escape(_nodeAttr(node,"Label"))+"\")","Common/Images/KeyPress.gif");
	dm.add("-");
	dm.add("Edit","editConditions("+ruleID+")","Common/Images/ViewPane.gif");
	dm.menuShow();
	event.cancelBubble = true;
	return false;
}
function insertLevel(parentID,ruleID){
	var label = prompt("Level's label (option):","");
	var ret = WS(CO("InsertGLCondition"),null,parentID||null,ruleID||null,0,"",encodeXML(label),"");
	if( showSOAPError(ret) )return;
	if( !confirm("Insert a rule to level ["+label+"]?") )return dataBind(oTree);
	showConditions(ret.value,MODE_INSERT_CHILD);
}
function pasteRule(ruleIDAfter,labelTo,ruleIDFrom,labelFrom){
	if( !confirm("Paste "+unescape(labelFrom)+" after "+unescape(labelTo)+"?") )return;
	copyToProgram(ruleIDFrom,ruleIDAfter);
	dataBind(ce);
}
function copyToProgram(ruleID,afterID){
	afterID = afterID || prompt("After ID:",'');
	if( !afterID )return;
	var ret = WS(CO("CopyGLCondition"),ruleID,afterID);
	if( showSOAPError(ret) )return;
}
function makeItChild(ruleID){
	var ret = WS(CO("CombineGLCondition"),ruleID);
	if( showSOAPError(ret) )return;
	dataBind(oTree);
}
function cloneGL(ruleID){
	var ret = WS(CO("CopyGLCondition"),ruleID,ruleID);
	if( showSOAPError(ret) )return;
	if( !confirm("Edit new rule?") )dataBind(oTree);
	else showConditions(ret.value,MODE_EDIT);
}
function shiftGL(ruleID,step){
	var ret = WS(CO("ShiftGLCondition"),ruleID,step);
	if( showSOAPError(ret) )return;
	dataBind(oTree);
}
function bodyContextMenu(x,y){
	var dm = new DropMenu("mnuFly");
	if( !dm.menuID )return false;
	dm.add("Edit Programs","addProgram()","Common/Images/Edit.gif");
	dm.add("Copy Program","copyProgram()","Common/Images/Edit.gif");
	dm.add("-");
	dm.add("Add Bank","addBank()","Common/Images/Edit.gif");
	dm.add("-");
	dm.add("Add Rule","addFirstRule()","Common/Images/Tree_Little.gif");
	dm.add("-");
	dm.add("Edit Conditions","editConditions(0)","Common/Images/ViewPane.gif");
	if( !x )dm.menuShow()
	else dm.menuShow(x,y);
	event.cancelBubble = true;
	return false;
}
function addBank(){
	var retVal = showModalDialog("Banks.aspx",null,"status:0");
	var ret = WS(CO("Bank_List"));
	var rs = getRSFromString(ret.value);
	fillSelect(rs,selBanks,"Name","ID");
	if( retVal.addedID )selBanks.value = retVal.addedID;
	changeBank();
}
function copyProgram(){
	var progName = prompt("Program Name:","");
	if( !progName )return;
	var ret = WS(CO("Program_Copy"),_programID(),progName);
	if( showSOAPError(ret) )return;
}
function addProgram(){
	var ret = showModalDialog("Programs.aspx?BankID="+_bankID(),null,"status:0;resizable:1");
	if( !ret )return;
	if( ret.addedID )changeBank(ret.addedID);
	if( ret.deletedID )changeBank();
	return;
	var progName = prompt("Program name:","");
	if( !progName )return;
	var ret = WS(CO("AddProgram"),encodeXML(progName),_bankID());
	if( showSOAPError(ret) )return;
	selProgs[selProgs.length] = new Option(progName,ret.value);
	selProgs[selProgs.length-1].selected = true;
	_programID(ret.value);
	document.title = "Program:"+progName;
	dataBind(oTree);
}
function deleteBank(){return alert("Under constraction!");
	if( !confirm("Delete "+selTiers[selTiers.selectedIndex].text+"?") )return;
	var ret = WS(CO("DeleteTier"),_tierID());
	if( showSOAPError(ret) )return;
	var index = selTiers.selectedIndex;
	selTiers.options.remove(index);
	_tierID( selTiers.length ? selTiers[Math.min(index,selTiers.length-1)].value : 0);
	//document.title = document.title.replace(" "+_tierID()," "+ret.value);
	dataBind(oTree);
}
function changeBank(progID){
	if( !checkWS(true) )return setTimeout(function(){return changeBank(progID);},1000);
	var ret = WS(CO("GetPrograms"),_bankID());
	if( showSOAPError(ret) )return;
	fillSelect(getRSfromDS(ret.value),selProgs,"Name","ID");
	if( _programID(progID) )setTimeout("dataBind(oTree)",100);
}
function changeRealTime(el){
	var ret = WS(CO("UpdateRealTime"),el.checked);
	if( showSOAPError(ret) )return false;
}
function changeTreeDebug(el){
	var ret = WS(CO("UpdateTreeDebug"),el.checked);
	if( showSOAPError(ret) )return false;
	dataBind(oTree);
}
function changeProgram(){
	setTimeout("dataBind(oTree)",100);
}
function changeApplID(){
	setTimeout("dataBind(oTree,true)",100);
}
function removeGLCondition(ruleID,label){
	if( !confirm("Permanently remove [ "+unescape(label)+" ] rule from Guide Lines?") )return;
	var ret = WS(CO("RemoveGLCondition"),ruleID);
	if( showSOAPError(ret) )return;
	if( _realTime() )dataBind(oTree);
}
function changeLabel(ruleID,label){
	label = trim(unescape(label));
	var newlabel = prompt("Change "+label+" to:",label);
	if( newlabel == label || newlabel == null )return;
	var ret = WS(CO("ChangeGLLabel"),ruleID,encodeXML(newlabel));
	if( showSOAPError(ret) )return;
	dataBind(oTree);
}
function addFirstRule(){
	showConditions('',MODE_INSERT);
}
function showConditions( ruleID,mode,editElement ){
	var params = new Array("Mode="+mode,"RuleID="+ruleID,"ProgramID="+_programID());
	var ret = showModalDialog("ShowCondition.aspx?"+params.join("&"),{editElement:editElement},"dialogWidth:500px;dialogHeight:200px;help:0;status:0;resizable:1");
	if( !ret )return null;
	if(editElement)return ret;
	if( !ret.doAnother )dataBind(oTree);
	else showConditions(ret.ruleID,ret.doAnother);
}
function editConditions( ruleID ){
	var pid = Math.abs(_programID());
	if( pid == 0 )return alert("Program must be selected in order to edit conditions.");
	var params = new Array("RuleID="+ruleID,"ProgramID="+pid);
	if( !showModalDialog("EditCondition.aspx?"+params.join("&")) )return;
	dataBind(oTree);
}
function dataBind(oTree,dontSaveState){
	oTree.treeNodeSrc = "GLRules.asmx/GetGLTree?programID="+_programID()+"&applID="+_applID();
	oTree.databind();
	_tier("");
}
function getPQInfo(){
	WS(function(ret){return cb(ret)},"GetPQInfo",_programID()||0,_applID()||0);
	function cb(ret){
		if( showSOAPError(ret) )return;
		gridPQInfo.recordset = ret.value;
		setTimeout(function(){gridPQInfo.toggleState = "-"},1000);
	}
}
//******* Dragin' ********
function onDrop(){
	var ret = WS(CO("MoveGLCondition"),event.nodeSrcXML.id,event.dragChild?null:event.nodeDestXML.id,event.dragChild?event.nodeDestXML.id:null,event.dragCopy);
	if( showSOAPError(ret) )return;
	if( event.dragCopy && confirm("Edit new rule?") )
		showConditions(ret.value,MODE_EDIT);
	if( _realTime() )dataBind(oTree);
}
// Helpers
function _adj(v){
	if( arguments.length > 0 )chkAdj.checked= v||false;
	return chkAdj.checked
}
function _rsInfo(){return xmlInfo.recordset}
function _realTime(){return eval(_rsInfo()("RealTime").value)}
function _bankID(id){
	if( arguments.length > 0 )selBanks.value = id;
	if( selBanks.length == 1 )selBanks.selectedIndex = 0;
	return selBanks.value||0;
}
function _programID(id){
	if( arguments.length > 0 )selProgs.value = id||0;
	if( selProgs.length == 1 )selProgs.selectedIndex = 0;
	var progID = selProgs.value||0;
	return _adj() ? -progID : progID;
}
function _tier(v){
	if( arguments.length )selTiers.value = v;
	return selTiers.value
}
function _applID(id){
	if( arguments.length > 0 )txtApplID.value = id;
	return txtApplID.value||0;
}
function _dragCopy(){return event.ctrlKey};
</SCRIPT>
